package com.kakarote.common.log.service.impl;


import com.kakarote.common.log.entity.OperateLogEntity;
import com.kakarote.common.log.service.MqMessageService;
import com.kakarote.common.log.service.OperateLogSaveService;
import com.kakarote.core.redis.Redis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

/**
 * @author: admin
 * @version: v1.0
 * @date:2023/10/7
 */
@Service
@ConditionalOnProperty(prefix = "wk.mq", name = "type", havingValue = "redis")
public class RedisMqMessageServiceImpl implements MqMessageService, OperateLogSaveService {

    @Autowired
    private Redis redis;

    @Override
    public void send(String topic, Object message) {
        redis.convertAndSend(topic, message);
    }

    /**
     * 保存操作日志
     *
     * @param entity entity
     */
    @Override
    public void saveOperateLog(OperateLogEntity.Entity.Builder entity) {
        send("operateLog", entity.build());
    }
}
